package dt.tradeAction;

import java.io.IOException;
import java.io.Reader;
import java.util.Map;
import java.sql.Date;

import org.apache.struts2.interceptor.SessionAware;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.opensymphony.xwork2.ActionSupport;

import dt.bankAction.AccountVO;

public class TradeAction extends ActionSupport implements SessionAware{
    
	private Map session;
	public static Reader reader;
	public static SqlMapClient sqlMapper;

	
	private AccountVO resultClass;
	private AccountVO paramClass;
	
	private static final long serialVersionUID = 1L;
	private int minCheck;
	private int result;
	private int startFlag;
	private double startRates;
	private double realRates;
	private int time_count;
	private String high_low;
	private int checkHL;
	private String minmin;
	private int endFlag;
	private int totalMoney;
	private String id;
	
	
	
	public TradeAction() throws IOException{
		reader = Resources.getResourceAsReader("sqlMapConfig.xml"); 
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); 
		reader.close();
	}
	
	
	public String execute() throws Exception {
	
		
		System.out.println("111111111");
		System.out.println(minmin);
		startFlag = 1;
		if (high_low.equals("HIGH")){
			checkHL = 0;
		} else if (high_low.equals("LOW")){
			checkHL = 1;
		}
		
		
		
		return SUCCESS;
	}
	
	public String form() throws Exception {
				
        System.out.println(session.get("id"));
		
		if(session.get("id") != null){
			
			resultClass = new AccountVO();

			id = session.get("id").toString();
		
			resultClass = (AccountVO)sqlMapper.queryForObject("account.select-account", id);
			
		    totalMoney = resultClass.getTotal_money();
		
			}
		
		System.out.println(totalMoney);
			
		return SUCCESS;
	}
	
	public String endResult() throws Exception {
		endFlag = 1;
		//System.out.println("111111111");
		//System.out.println(minmin);
		
		return SUCCESS;
	}
	
	

	public int getMinCheck() {
		return minCheck;
	}

	public void setMinCheck(int minCheck) {
		this.minCheck = minCheck;
	}

	public int getStartFlag() {
		return startFlag;
	}

	public void setStartFlag(int startFlag) {
		this.startFlag = startFlag;
	}

	public double getRealRates() {
		return realRates;
	}

	public void setRealRates(double realRates) {
		this.realRates = realRates;
	}

	public String getHigh_low() {
		return high_low;
	}

	public void setHigh_low(String high_low) {
		this.high_low = high_low;
	}

	public int getTime_count() {
		return time_count;
	}

	public void setTime_count(int time_count) {
		this.time_count = time_count;
	}

	public int getCheckHL() {
		return checkHL;
	}

	public void setCheckHL(int checkHL) {
		this.checkHL = checkHL;
	}

	
	public double getStartRates() {
		return startRates;
	}

	public void setStartRates(double startRates) {
		this.startRates = startRates;
	}

	public String getMinmin() {
		return minmin;
	}

	public void setMinmin(String minmin) {
		this.minmin = minmin;
	}

	public int getEndFlag() {
		return endFlag;
	}

	public void setEndFlag(int endFlag) {
		this.endFlag = endFlag;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}


	public Map getSession() {
		return session;
	}


	public void setSession(Map session) {
		this.session = session;
	}


	public int getTotalMoney() {
		return totalMoney;
	}


	public void setTotalMoney(int totalMoney) {
		this.totalMoney = totalMoney;
	}


	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}


}
